package com.imy.touch.root.command;

import android.view.MotionEvent;

import com.imy.touch.constant.MotionEventExt;

public class ProtocolCreate {

  /**
   * String path="/data/user/0/com.imy.testserver/1.png";
   *
   * @param path
   * @return
   */
  public static String createTakScreen(String path) {
    StringBuilder builder = new StringBuilder();
    builder.append(ProtocolConstant.TAKE_SCREEN);
    builder.append(" ");
    builder.append(path);
    return builder.toString();
  }

  public static String createMove(int x,int y,int id){
    return formatXY(MotionEvent.ACTION_MOVE,x,y,id);
  }
  public static String createDown( int x, int y, int id) {
   return formatXY(MotionEvent.ACTION_DOWN,x,y,id);
  }
  public static String createUp(int x,int y ,int id){
    return formatXY(MotionEvent.ACTION_UP,x,y,id);
  }
  private static String formatXY(int action, int x, int y, int id) {
    StringBuilder builder = new StringBuilder();
    builder.append(ProtocolConstant.GESTURE);
    builder.append(" ");
    builder.append(changeAction(action));
    builder.append(" ");
    builder.append(x);
    builder.append(" ");
    builder.append(y);
    builder.append(" ");
    builder.append(id);
    return builder.toString();
  }

  private static String changeAction(int action) {
    if (action == MotionEvent.ACTION_DOWN) {
      return "d";
    } else if (action == MotionEvent.ACTION_MOVE) {
      return "m";
    } else if (action == MotionEvent.ACTION_UP) {
      return "u";
    }
    return "";
  }
}
